import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter);
// mongodb  mongo  mongod mongoose
// router  routes route
// import HomeCom from './components/HomeCom';
// import ProductCom from './components/ProductCom';
// import AboutCom from './components/AboutCom';
// import NoteFoundCom from './components/NoteFoundCom';

// 路由的懒加载：当切换路由的时候 才会加载路由组件
const HomeCom = ()=>import('./components/HomeCom');
const ProductCom = ()=>import('./components/ProductCom');
const AboutCom = ()=>import('./components/AboutCom');
const NoteFoundCom = ()=>import('./components/NoteFoundCom');
const ComA = ()=>import('./components/ComA');
const ComB = ()=>import('./components/ComB');
let router = new VueRouter({
    mode:"history",
    routes:[
      {
        name:"index",
        path:"/",
        // component:HomeCom
        redirect:"/home"
      },{ 
        name:"home",
        path:"/home",
        component:HomeCom,
        children:[{
            name:"a",
            path:"a",
            component:ComA
        },{
          name:"b",
          path:"b",
          component:ComB
        }]
      },
      {
        name:"product",
        path:"/product",
        component:ProductCom,
        beforeEnter:function(to,from,next){
          console.log("beforeEnter",to,from);
          next();
        }
      },
      {
        name:"about",
        path:"/about/:id",
        component:AboutCom  
      },
      {
        name:"404",
        path:"/*",
        component:NoteFoundCom  
      }
    ],
    linkActiveClass:'myactive'
})
// beforeEach使用的最多：校验权限
router.beforeEach(function(to,from,next){
  console.log("全局路由守卫beforeEach",to,from);
  next();
})

router.afterEach(function(to,from){
    console.log("全局路由守卫afterEach",to,from);
})


export default router;